package com.ls.lserp.modules.job.service;

import java.sql.SQLException;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


import com.ls.lserp.common.service.CrudService;

import com.ls.lserp.dbaccess.Dao.OgnizationPEntityMapper;
import com.ls.lserp.dbaccess.Entity.OgnizationBarandEntity;
import com.ls.lserp.dbaccess.Entity.OgnizationPEntity;
import com.ls.lserp.modules.sys.dao.BrandDao;
import com.ls.lserp.modules.sys.entity.Brand;


/**
 * Created by zhouyang on 2017/9/15.
 */
@Service
@Transactional(readOnly = false)
public class OgnizationSyncService extends CrudService<OgnizationPEntityMapper, OgnizationPEntity> {

    @Autowired
    private OgnizationPEntityMapper ognizationPEntityMapper;
    @Autowired
    private BrandDao brandDao;

    /**
     * @Title       : findAllList
     * @Description : 取得ERP最新数据
     * @return ognizationPEntityMapper
     * @throws SQLException
     * @return      : List<UploadFile>
     *
     * @author      : yang.zhou
     * @date        : 2017年9月15日
     */
    public List<OgnizationPEntity> findAllList(OgnizationPEntity ognizationPEntity) throws SQLException {
        ognizationPEntity.setDeleteFlag("0");
        // 设置组织类别为平台客户
        ognizationPEntity.setOgnizationCategoryCd("CUSTOMER_CATEGORY-CUSTOMER_MTM");
        return ognizationPEntityMapper.findAllList(ognizationPEntity);
    }
    
    /**
     * @Title       : findAllBrandList
     * @Description : 取得ERP品牌最新数据
     * @throws SQLException
     * @return      : List<Brand>
     * @author      : X.T.H
     * @date        : 2018年06月19日
     */
    public List<Brand> findAllBrandList(Brand brand) throws SQLException {
        return brandDao.findAllList(brand);
    }
    
    /**
     * @Title       : findAllBrandList
     * @Description : 取得ERP品牌最新数据
     * @throws SQLException
     * @return      : List<Brand>
     * @author      : X.T.H
     * @date        : 2018年06月19日
     */
    public List<OgnizationBarandEntity> findAllOgBrandList(Brand brand) throws SQLException {
        return brandDao.findAllOgBrandList(brand);
    }

    /**
     * @Title       : dataSync
     * @Description : 同步数据
     * @param uploadFile
     * @throws SQLException
     * @return      : void
     *
     * @author      : zhigang.gao
     * @date        : 2017年7月6日
     */
    public void dataSync(OgnizationPEntity ognizationPEntity) throws SQLException {

        // 清空旧数据 Ognization
        ognizationPEntityMapper.deleteAll(ognizationPEntity);

        // 插入新数据 Ognization
       for (int i =0;i<ognizationPEntity.getOgnizationPEntityList().size();i++) {
           ognizationPEntity.getOgnizationPEntityList().get(i);
           ognizationPEntityMapper.insertByList(ognizationPEntity.getOgnizationPEntityList().get(i));
       }
    }
    
    /**
     * @Title       : dataSync
     * @Description : 同步数据
     * @param uploadFile
     * @throws SQLException
     * @return      : void
     *
     * @author      : X.T.H
     * @date        : 2018年6月19日
     */
    public void dataSync(List<OgnizationBarandEntity> ognizationBarandList) throws SQLException {

        // 清空旧数据 OgnizationBarand
    	brandDao.deleteAllOgBrand();

        // 插入新数据 OgnizationBarand
       for (int i =0;i<ognizationBarandList.size();i++) {
           brandDao.insertOgBrandByList(ognizationBarandList.get(i));
       }
    }
    
    /**
     * @Title       : dataSync
     * @Description : 同步数据
     * @param brand
     * @throws SQLException
     * @return      : void
     *
     * @author      : X.T.H
     * @date        : 2018年6月19日
     */
    public void dataSync(Brand brand) throws SQLException {

        // 清空旧数据 Brand
    	brandDao.deleteAll();

        // 插入新数据 Brand
       for (int i =0;i<brand.getBrandList().size();i++) {
           brandDao.insert(brand.getBrandList().get(i));
       }
    }
}
